<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <link rel="stylesheet" href="./css/layui.css" />
    <link rel="stylesheet" href="./font/iconfont.woff" />
  </head>
  <style>
    #demo1 {
        width: 300px;
      background-color: #fff;
      color: black;
      border: 1px solid black;
    }
    #demo1 span {
        margin-left: 0px;
    }
  </style>
  <body>
    <button class="layui-btn" id="demo1" disabled="false">
      <span>请选择上级区域</span>
      <i class="layui-icon layui-icon-down layui-font-12"></i>
    </button>
    <form class="layui-form" action="">
        <div class="layui-form-item">
          <div><label class="layui-form-label">输入框</label></div>
          <div class="layui-input-block">
            <input type="text" name="title" label="ghfhfg" required  lay-verify="required" placeholder="请输入标题" autocomplete="off" class="layui-input">
          </div>
        </div>
      </form>
    <script src="./jquery-3.6.1.js"></script>
    <script src="./layui.js"></script>
    <script>
      layui.use("dropdown", function () {
        var dropdown = layui.dropdown;
        dropdown.render({
          elem: "#demo1", //可绑定在任意元素中，此处以上述按钮为例
          data: [
            {
              title: "menu item 1",
              id: 100,
              href: "#",
            },
            {
              title: "menu item 2",
              id: 101,
              href: "{{d.root}}/", //开启超链接
              target: "_blank", //新窗口方式打开
            },
            { type: "-" },
            {
              title: "menu item 3",
              id: 102,
              type: "group", //菜单类型，支持：normal/group/parent/-
              child: [
                {
                  title: "menu item 3-1",
                  id: 103,
                },
                {
                  title: "menu item 3-2",
                  id: 104,
                  child: [
                    {
                      title: "menu item 3-2-1",
                      id: 105,
                    },
                    {
                      title: "menu item 3-2-2",
                      id: 106,
                    },
                  ],
                },
                {
                  title: "menu item 3-3",
                  id: 107,
                },
              ],
            },
            { type: "-" },
            {
              title: "menu item 4",
              id: 108,
            },
            {
              title: "menu item 5",
              id: 109,
              child: [
                {
                  title: "menu item 5-1",
                  id: 11111,
                  child: [
                    {
                      title: "menu item 5-1-1",
                      id: 2111,
                    },
                    {
                      title: "menu item 5-1-2",
                      id: 3111,
                    },
                  ],
                },
                {
                  title: "menu item 5-2",
                  id: 52,
                },
              ],
            },
            { type: "-" },
            {
              title: "menu item 6",
              id: 6,
              type: "group",
              isSpreadItem: false,
              child: [
                {
                  title: "menu item 6-1",
                  id: 61,
                },
                {
                  title: "menu item 6-2",
                  id: 62,
                },
              ],
            },
          ],
          id: "demo1",
          //菜单被点击的事件
          click: function (obj) {
            $('span').html(obj.title)
            console.log(obj);
            layer.msg("回调返回的参数已显示再控制台");
          },
        });
      });
    </script>
  </body>
</html>
